import { SERVICES } from '@/common';
import { SettingOutlined } from '@ant-design/icons';
import { history } from '@umijs/max';
import { Avatar, Dropdown, message } from 'antd';
import React from 'react';
import styles from './RightContent.less';

export interface RightContentProps {
	[key: string]: any;
}

const items = [
	{
		key: 'exit',
		icon: <SettingOutlined />,
		label: (
			<span
				onClick={() => {
					localStorage.removeItem('vehicle_token');
					setTimeout(() => {
						history.push('/login');
						message.success('退出登录成功');
					}, 1000);
				}}
			>
				退出登录
			</span>
		),
	},
];

const RightContent: React.FC<RightContentProps> = (props) => {
	return (
		<Dropdown menu={{ items }}>
			<div className={styles.header}>
				<Avatar src={SERVICES + props.cover} />
				<span className={styles.name}>{props.nickname || props.name}</span>
			</div>
		</Dropdown>
	);
};

export default RightContent;
